/*
 *      Author:	Wolter Hellmund
 *      Email:	wolterh6@gmail.com
 *      --------------------------------------
 * 	    Interface source code
 *      --------------------------------------
 *      Copyright 2009. All Rights Reserved.
 */

#include "interface.hpp"

// Actions (axn)
void MainWindow::axn_ply()
{
	handy_msgbox("Request","Stream play");
	return;
}

void MainWindow::axn_stp()
{
	handy_msgbox("Request","Stream stop");
	return;
}

void MainWindow::axn_add()
{
	handy_msgbox("Request","Add station");
	return;
}

void MainWindow::axn_del()
{
	handy_msgbox("Request","Delete station");
	return;
}

void MainWindow::axn_abt()
{
	handy_msgbox("Request","About dialog");
	return;
}

void MainWindow::combo_loadFromRecord(Record record)
{
	for (int i = 0; i < record.vec_stns.size(); i++)
	{
		combo_add( record.vec_stns[i] );
	}
	return;
}

void MainWindow::combo_add(string what)
{
	Gtk::TreeModel::Row row = *(combo_tree->append());
	row[combo_column.combo_item] = what;
	return;
}

// Constructor
MainWindow::MainWindow(Record record)
:	glade(),
	window(),
	toolbar(),
	btn_add(), btn_del(), btn_ply(), btn_stp(), btn_abt(),
	combo(), combo_tree(),
	pbar()
{	
	// Get the interface from the glade file
	glade = Gnome::Glade::Xml::create("data/bambox.glade");
	
	// Assign widgets
	glade->get_widget("window",window);
	glade->get_widget("toolbar",toolbar);
		glade->get_widget("btn_ply",btn_ply);
		glade->get_widget("btn_stp",btn_stp);
		glade->get_widget("btn_add",btn_add);
		glade->get_widget("btn_del",btn_del);
		glade->get_widget("btn_abt",btn_abt);
	glade->get_widget("combo",combo);
	glade->get_widget("pbar",pbar);
	
	// Setup widgets
		// Window
	window->set_title(PKG_NAME); //--> PKG_NAME macro defined in global.hpp. Already set in the gladefile though...
	
		// ComboBox
	combo_tree = Gtk::ListStore::create(combo_column);	
	combo->set_model(combo_tree);
	combo_loadFromRecord(record);
	//combo->pack_start(combo_column.combo_item); --> not needed by some alien reason :)
	
	// Connect the widgets
	btn_ply->signal_clicked().connect(sigc::mem_fun(this,&MainWindow::axn_ply));
	btn_stp->signal_clicked().connect(sigc::mem_fun(this,&MainWindow::axn_stp));
	btn_add->signal_clicked().connect(sigc::mem_fun(this,&MainWindow::axn_add));
	btn_del->signal_clicked().connect(sigc::mem_fun(this,&MainWindow::axn_del));
	btn_abt->signal_clicked().connect(sigc::mem_fun(this,&MainWindow::axn_abt));
	
	// Show the window and all the widgets
	Gtk::Main::run(*window);
}

// Destructor
MainWindow::~MainWindow() 
{
	MainWindow::axn_stp();
	handy_msgbox("Report","Exiting flawlessly");
}

// Initializer function
void ui_init(int argc, char** argv)
{
	// Start GTK
	Gtk::Main kit(argc,argv);
	// Make the record and load it
	Record Bambox_record;
	// Make the window
	MainWindow Bambox_window(Bambox_record);
	// Save the record before exit
	Bambox_record.save();
	// Exit, though return here is just a formality
	return;
}
